package com.mate.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.mate.model.MMovie;
import com.mate.model.MRank;
import com.mate.model.MWish;
import com.mate.model.vo.MovieDetailVo;
import com.mate.service.IMMovieService;
import com.mate.service.IMRankService;
import com.mate.service.IMWishService;
import com.mate.utils.MovieInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 热门评论表 前端控制器
 * </p>
 *
 * @author boy
 * @since 2020-05-08
 */
@RestController
@RequestMapping("/movie")
public class MovieController {

    @Resource
    private IMMovieService movieService;

    @Resource
    private IMWishService wishService;

    @Resource
    private IMRankService rankService;

    @RequestMapping("/queryMovies")
    public List<MMovie> queryMovies(String type) {
        return movieService.selectList(new EntityWrapper<MMovie>().and("type = {0}", type).orderBy("id", false));
    }

    @RequestMapping("/queryMoviesBy")
    public List<MMovie> queryMoviesBy(String words) {
        return movieService.selectList(new EntityWrapper<MMovie>().like("title", "%" + words + "%").orderBy("id", false));
    }

    @RequestMapping("/queryDetail")
    public MovieDetailVo queryDetail(String id) {
        return MovieInfo.getDetail(id);
    }

    @RequestMapping("/ranks")
    public List<MRank> ranks() {
        return rankService.selectList(new EntityWrapper<>());
    }

    @RequestMapping("/wish")
    public List<MWish> wish() {
        return wishService.selectList(new EntityWrapper<>());
    }

}
